import { defineStore } from 'pinia'
import getAllSurvey from '@/request/getAllSurvey'

export default defineStore('allSurveyData', {
  state: () => ({
    allSurvey: [],
    stopSurvey: [],
    collectSurvey: [],
    showType: 'collect', // all  stop  collect
  }),
  actions: {
    async update() {
      const allSurvey = await getAllSurvey()
      if (!allSurvey) return
      this.allSurvey = allSurvey
      const stopSurvey = []
      const collectSurvey = []
      allSurvey.forEach(s => {
        if (s.over) stopSurvey.push(s)
        else collectSurvey.push(s)
      })
      this.stopSurvey = stopSurvey
      this.collectSurvey = collectSurvey
    },
  },
})
